#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Partrolmanagement_Paramter_instances = BaseConstant.Partrolmanagement_Paramter
# nav_name = "工作"
# plugin_name = "巡更管理"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-巡更管理",'name','巡更管理']
report_desc_keys = "巡更管理添加"

class patrol_manage_factory():

	def open_patrolmanagement_plug(self,driver,file_path):
		try:
			element_oprate_instance.element_click(nav_name,file_path)
			driver.swipe(400,1000,400,50,1200)
			# 点击"巡更管理"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
			#等待巡更管理页面内容进行加载，加载完成之后进行页面确认并界面
			element_oprate_instance.element_save_pic(file_path, 'open_patrolmanagement_plug_successful')
			
		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_patrolmanagement_plug_fail')
			raise

	def add_patrolmanage_case(self,driver,file_path):
		try:
			#点击添加
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.report_new_id, file_path)
			#选择等级
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.grade_type_id, file_path)
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.grade_type_keys, file_path)
			#选择类型
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.event_type_id, file_path)
			#driver.find_element_by_name(grade_type_keys.decode("utf-8")).click()			
			#选择大类
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.main_type_id, file_path)
			#driver.find_element_by_name(grade_type_keys.decode("utf-8")).click()			
			#选择小类
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.sub_type_id, file_path)
			#driver.find_element_by_name(grade_type_keys.decode("utf-8")).click()
			#选择位置
			#driver.find_element_by_id(location_desc_id).click()
			#添加描述
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.report_desc_id, file_path)
			element_oprate_instance.element_send_keys(Partrolmanagement_Paramter_instances.report_desc_id,report_desc_keys.decode("utf-8"), file_path)
			#添加图片
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.media_view_id, file_path)
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.add_photo_id, file_path)
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.select_photo_id, file_path)
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.comfirm_photo_id, file_path)
			#截图
			element_oprate_instance.element_save_pic(file_path, 'add_patrolmanage_case_successful')
			#点击提交
			element_oprate_instance.element_click(Partrolmanagement_Paramter_instances.btn_report_id, file_path)

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'add_patrolmanage_case_fail')
			raise	
if __name__ == '__main__':
	unittest.main()			
